import { addOffterApi } from "@/api/offter";
import { baseURL } from "@/api/request";
import { userStore } from "@/mobx/store";
import { PlusOutlined } from "@ant-design/icons";
import { ModalForm, ProForm, ProFormDateRangePicker, ProFormSelect, ProFormText, ProFormColorPicker, ProFormDigit, ProFormDateTimeRangePicker, ProFormUploadButton, ProFormDateTimePicker } from "@ant-design/pro-components";
import { useRequest } from "ahooks";
import { Button, Form, message } from "antd";

const OfferAdd = () => {
    const [form] = Form.useForm<FormOffterTypes>();
    const addUsers = useRequest(addOffterApi, {
        manual: true,
        onSuccess: (res) => {
            console.log(res);
        }
    })
    const { Mydata: { userInfo } } = userStore()
    return (
        <div>
            <ModalForm<FormOffterTypes>
                title="新建offter"
                trigger={
                    <Button type="primary">
                        <PlusOutlined />
                        新建Offter
                    </Button>
                }
                width={300}
                form={form}
                autoFocusFirstInput
                modalProps={{
                    destroyOnClose: true,
                    onCancel: () => console.log('run'),
                }}
                onFinish={async (values) => {

                    addUsers.run({ ...values, name: 'wkk', phone: '13467594356', userInfo: userInfo, desc: values.desc[0].response.path })

                    message.success('提交成功');
                    return true;
                }}
            >
                <ProFormText
                    name="company"
                    label="公司名称"
                    width='sm'
                    rules={[{ required: true, message: '请输入名称' }]}
                />
                <ProFormDigit
                    name="salary"
                    label="薪资"
                    width='sm'
                    rules={[{ required: true, message: '请输入薪资' }]}
                />
                <ProFormDigit
                    name="tips"
                    label="公司类型"
                    width='sm'
                    rules={[{ required: true, message: '请选择公司类型' }]}
                />
                <ProFormText
                    name="city"
                    label="所在城市"
                    width='sm'
                    rules={[{ required: true, message: '请选择所在城市' }]}
                />
                <ProFormDateTimePicker
                    name="time"
                    label="日期时间"
                    fieldProps={{
                        format: (value) => value.format('YYYY-MM-DD'),
                    }}
                />
                <ProFormUploadButton
                    name="desc"
                    label="图片"
                    max={2}
                    fieldProps={{
                        name: 'file',
                    }}
                    action={baseURL + '/pro/uplodafile'}
                />
            </ModalForm>
        </div>
    )
}

export default OfferAdd